package com.sxy.config;

import com.sxy.controller.Interceptor.ProjectInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
@Configuration
@ComponentScan({"com.sxy.controller","com.sxy.config"})
@EnableWebMvc
@EnableTransactionManagement
//在SpringMvc配置类中实现WebMvcConfigurer接口可以直接在此类中配置过滤器和拦截器
//使用此方法配置拦截器或过滤器侵入性较强
public class SpringMvcConfig implements WebMvcConfigurer {
    @Autowired
    private ProjectInterceptor projectInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(projectInterceptor).addPathPatterns("/books");
    }
}
